package com.superman.supermarket.client.composite.search;

import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;
import com.superman.mvpframe.client.dom.HasInputHandlers;
import com.superman.mvpframe.client.dom.InputHandler;
import com.superman.supermarket.client.widget.button.BackButton;
import com.superman.supermarket.client.widget.search.SearchBox;

/**
 * 搜索顶部模块
 * 
 * @author superman
 * @version 2018年8月13日下午10:19:28
 */
public class SearchTopModule extends FlowPanel implements HasClickHandlers, HasInputHandlers {

	private SearchBox searchBox;
	private HTML searchBtn;

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年8月13日 下午10:19:48
	 */
	public SearchTopModule() {
		this.setSize("9.6rem", "1.2rem");
		this.getElement().addClassName("flex-h flex-vc flex-hs");
		this.getElement().getStyle().setProperty("padding", "0 0.2rem");
		this.getElement().getStyle().setProperty("background", "#fff");
		this.getElement().getStyle().setProperty("fontSize", "18px");

		this.add(new BackButton());
		this.add(initSearchBox());
		this.add(initSearchButton());
	}

	@Override
	public HandlerRegistration addClickHandler(ClickHandler handler) {
		return searchBtn.addClickHandler(handler);
	}

	@Override
	public HandlerRegistration addInputHandler(InputHandler handler) {
		return searchBox.addInputHandler(handler);
	}

	/**
	 * 获取关键词
	 * 
	 * @author superman
	 * @version 2018年8月13日 下午10:39:40
	 * @return value
	 */
	public String getValue() {
		return searchBox.getValue();
	}

	private SearchBox initSearchBox() {
		searchBox = new SearchBox();
		searchBox.setPlaceHolder("在这里搜索你想要的商品");
		searchBox.getElement().getStyle().setProperty("marginLeft", "0.1333333rem");
		return searchBox;
	}

	private Widget initSearchButton() {
		searchBtn = new HTML("搜索");
		searchBtn.getElement().getStyle().setProperty("fontSize", "14px");
		searchBtn.getElement().getStyle().setProperty("color", "#666");
		searchBtn.getElement().getStyle().setProperty("padding", "0.2666667rem 0.4rem");
		return searchBtn;
	}

}
